package ssm.blog.service.impl;

import org.springframework.stereotype.Service;
import ssm.blog.dao.QuotationMapper;
import ssm.blog.entity.Quotation;
import ssm.blog.entity.QuotationExample;
import ssm.blog.service.QuotationService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: lyon
 * @description: 语录 服务层
 * @author: Lyon
 * @create: 2018-06-04 12:03
 **/
@Service
public class QuotationServiceImpl implements QuotationService {
    @Resource
    QuotationMapper mapper;
    @Override
    public int add(Quotation quotation) {
        quotation.setStatu(1);
        return mapper.insert(quotation);
    }

    @Override
    public List<Quotation> listByKeyword(String keyword) {
        QuotationExample example=new QuotationExample();
        example.setOrderByClause("id desc");
        example.createCriteria().andTitleLike("%"+keyword+"%");
        return mapper.selectByExample(example);
    }

    @Override
    public List<Quotation> list(Boolean down) {
        QuotationExample example=new QuotationExample();
        if(down){
            example.setOrderByClause("id desc");
        }else{
            example.setOrderByClause("id asc");
        }
        return mapper.selectByExample(example);
    }
    @Override
    public Quotation selectById(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateById(Quotation quotation) {
        return mapper.updateByPrimaryKeySelective(quotation);
    }

    @Override
    public int deleById(Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deles(List<Integer> ids) {
        QuotationExample example=new QuotationExample();
        example.createCriteria().andIdIn(ids);
        return mapper.deleteByExample(example);
    }

    @Override
    public int count() {
        QuotationExample example=new QuotationExample();
        return mapper.countByExample(example);
    }
}
